# -*- coding: utf-8 –*-
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.core import serializers
from django.utils import simplejson

from apps.amway.models import Inventario

def ver_estadisticas(request):
    data = []
    inventario = Inventario.objects.filter(usuario=request.user)
    
    dict =  {	'chart' : { 'caption' : "Inventario" ,
                            'xAxisName' : "Productos", 'yAxisName' : "Cantidad" },
                'data'  : []
            }   
    
    for p in inventario:        
        data_dict = { 'label' : '%s'  % p.producto.descripcion, 'value' : p.existencias }       
        data.append(data_dict)
       
    
    dict["data"] = data   
    json = simplejson.dumps(dict)    
    return HttpResponse(json, mimetype='application/javascript')
    
    
    
    #for p in inventario:        
    #    data.append([p.producto.descripcion.encode('utf-8'), p.existencias])
    #
    #
    #
    #
    #return render_to_response("estadisticas/ver_estadisticas.html",
    #                          { 'data' : data },
    #                            context_instance=RequestContext(request))
    #for p in inventario:        
    #    dict = { 'descripcion' : '%s'  % p.producto.descripcion, 'existencias' : p.existencias }       
    #    data.append(dict)
    #
    #json = simplejson.dumps(data)   
    #return HttpResponse(json, mimetype='application/javascript')